public class Test {
    public int minSubArrayLen(int target, int[] nums) {
        int n = nums.length, sum = 0, len = Integer.MAX_VALUE;
        for(int left = 0, right = 0; right < n; right++) {
            sum += nums[right];//进窗口
            while(sum >= target) {
                len = Math.min(len,right - left + 1);//更新结果
                sum -= nums[left++];//出窗口
            }
        }
        return len == Integer.MAX_VALUE ? 0 : len;
    }

    public int lengthOfLongestSubstring(String ss) {
        char[] s = ss.toCharArray();

        int[] hash = new int[128];//用数组模拟哈希表
        int left = 0, right = 0, n = ss.length();
        int ret = 0;
        while(right < n){
            hash[s[right]]++;
            while(hash[s[right]] > 1)
                hash[s[left++]]--;//出窗口
            ret = Math.max(ret, right - left + 1);//更新结果
            right++;
        }
        return ret;
    }


}
